package web.stu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import web.stu.model.entity.Class;
import web.stu.model.entity.User;

import java.util.List;

/**
 * @author administer
 * @description 针对表【class(班级表)】的数据库操作Mapper
 * @createDate 2025-05-13 19:55:10
 * @Entity web.stu.model.entity.Class
 */
@Mapper
public interface ClassMapper extends BaseMapper<Class> {
    /**
     * 统计班级学生数量
     *
     * @param id
     * @return
     */
    int countByClassId(Integer id);

    /**
     * 查询学生班级是否存在该班级id
     *
     * @param id
     * @return
     */
    @Select("select count(*) from student_class where class_id = #{id}")
    Integer countClassStudentClass(@Param("id") Integer id);


    /**
     * 根据id统计班级人数
     *
     * @param classId
     * @return
     */
    @Select("select count(*) from student_class where class_id = #{classId}")
    Integer getStuCountByClassId(@Param("classId") Integer classId);

    /**
     * 根据班级id 获取 学生ids
     *
     * @param classId
     * @return
     */
    @Select("select student_id from student_class where class_id = #{classId} ")
    List<Integer> getUsersByClassId(@Param("classId") Integer classId);

    /**
     * 根据教师id获取班级列表
     *
     * @param teacherId
     * @return
     */
    @Select("select * from class where id in (select class_id from teacher_course where teacher_id = #{teacherId})")
    List<Class> getClassByTeacherId(@Param("teacherId") Integer teacherId);

    /**
     * 查询班级学生是否有记录
     *
     * @param studentIds
     * @param classId
     * @return
     */
    Integer getCountByStudentClassId(@Param("studentIds") List<Integer> studentIds, @Param("classId") Integer classId);

    int addStudentsByClass(@Param("studentIds") List<Integer> studentIds,@Param("classId") Integer classId);


    List<User> getStudentListDontSelectClass();
}





